<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>

<!DOCTYPE html>
<html>
  <head>
    <title>教材吧-用户登录</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	<%@ include file="/base/jsp/includeweb.jsp"%>
    <link type="text/css" rel="stylesheet" href="${path}/base/css/user.css"/>
  </head>
  <body>
  <%@ include file="/base/jsp/header.jsp"%>
  <%@ include file="/base/jsp/search-header.jsp"%>
  <div id="content-wrapper" class="content-wrapper border-top-org clear">
    <iframe name="login_iframe" width=0 height=0 style="visibility: hidden;"></iframe>
    <h2>登录教材吧</h2>
    <div class="login-wrapper">
        <form id="form1" name="form1" target="login_iframe" method="post" action="" onsubmit="login()">
        <div><input type="text" name="username" id="username" style="*margin-bottom:-3px;border-bottom:none;" value="用户名/邮箱" class="login-input border-radius-top"/></div>
        <div><input type="text" name="pwd-text" id="pwd-text" value="密码" class="login-input border-radius-bottom"/></div>
        <div><input type="password" name="password" id="password" value="" class="hide login-input border-radius-bottom"/></div>
        <div class="login-but-wrapper"><input id="subBtn" type="button" value="立即登录" onclick="login()"/></div>
        <div class="login-tip-wrapper"><a href="findpfirst.do?isM=1">忘记密码?</a> | <span id="qq_login_btn"></span>
        <!--<a href="#">快速登录</a> --></div>
      </form>
    </div>
  </div>
  <%@ include file="/base/jsp/footer.jsp"%>
  </body>
  <script type="text/javascript">
  var tipu = '用户名/邮箱';
  var tipp = "密码";
  var userid = "${sessionScope.userid}";
  if(isDefine(userid)){
      location.href="weborders.do?isM=1&userid="+userid;
  }
  
  //调用QC.Login方法，指定btnId参数将按钮绑定在容器节点中
   QC.Login({
       //btnId：插入按钮的节点id，必选
       btnId:"qq_login_btn",    
       //用户需要确认的scope授权项，可选，默认all
       scope:"all",
       //按钮尺寸，可用值[A_XL| A_L| A_M| A_S|  B_M| B_S| C_S]，可选，默认B_S
       size: "B_M"
   },function(oInfo, oOpts){
      if(QC.Login.check()){
         QC.Login.getMe(function(openId, accessToken){
            requestWithoutCheck("findByQQUser.do","qq="+openId,function(data){
              if(data.username == '' || data.sName == '' || data.dmName == '' || data.mjName == '' || data.mail == ''){
                  alert("欢迎您使用QQ号登录教材吧，请先完善您的信息");
                  location.href= "addinfo.do?id="+data.id+"&username="+oInfo.nickname+"&token="+openId;
              }else{
                  var query = "qqNumber="+openId;
                  request("Mlogin.do",query,function(data){
                     username = data.username;
                     userid = data.id;
                     entranceYear = $.formatDate("yyyy",data.entranceDate);
                     var yearCode = getYearCode();
                     location.href="searchschool.do?school="+data.sName+"&scode="+data.sCode+"&depart="+data.dmName+"&dcode="+data.dCode+"&major="+data.mjName+"&mcode="+data.mCode+"&yearCode="+yearCode+"&sid="+data.sid+"&did="+data.dmid+"&mid="+data.mjid;
                  })
              }
            })
         })
      }
   },function(opts){
      
   });
   
   
  function login(){
     var username = $("#username").val();
     var password = $("#password").val();
     if(username=='' || password=="" || username==tipu || password==tipp){
            alert("请输入用户名和密码");
            return;
      }
      var query = "username="+username+"&password="+$.md5(password);
      request("Mlogin.do",query,function(data){
          username = data.username;
          userid = data.id;
          //nameGlobal = data.name;
          //phoneGlobal = data.phone;
          entranceYear = $.formatDate("yyyy",data.entranceDate);
          var yearCode = getYearCode();
          location.href="searchschool.do?school="+data.sName+"&scode="+data.sCode+"&depart="+data.dmName+"&dcode="+data.dCode+"&major="+data.mjName+"&mcode="+data.mCode+"&yearCode="+yearCode+"&sid="+data.sid+"&did="+data.dmid+"&mid="+data.mjid;
      })
  }
  var pwdtext = $('<div><input type="text" name="pwd-text" id="pwd-text" value="密码" class="login-input border-radius-bottom"/></div>');
  var pwd = $('<div><input type="password" name="password" id="password" class="login-input border-radius-bottom"/></div>');
  $(function(){
       $("#pwd-text").focusin(function(){
           //$(this).blur();
           //$(this).hide();
           $(this).parent().remove();
           $("input[name=password]").show();
           $("#password").focus();
       });
       
       /*$("#password").focusout(function(){
          if($(this).val() == ""){
            //$(this).hide();
            $(this).parent().remove();
            //$("input[name=password]").hide();
            //$("input[name=pwd-text]").show();
            pwdtext.insertBefore(".login-but-wrapper");
            pwdtext.find("input[name=pwd-text]").focusin(function(){
                 $(this).parent().remove();
                 pwd.insertBefore(".login-but-wrapper");
            });
          }
       });
       */
     
     $("#username").focus(function(){
       if($(this).val() == tipu){
           $(this).val("");
       }
     });
     
     $("#username").blur(function(){
          if($(this).val() == ""){
           $(this).val(tipu);
       }
     });
  })
  </script>
</html>